home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTPtrHashMap<K,T,H,EQ> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tphdict.h> RWTPtrHashMap<K,T,H,EQ> m; PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!! IIIIffff yyyyoooouuuu hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd hhhheeeerrrreeee.... OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ffffoooorrrr RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhDDDDiiiiccccttttiiiioooonnnnaaaarrrryyyy described in Appendix A. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This class maintains a pointer-based collection of associations of type ppppaaaaiiiirrrr<<<<KKKK**** ccccoooonnnnsssstttt,,,, TTTT****>>>>. These pairs are stored according to a hash object of type HHHH. HHHH must provide a hash function on elements of type KKKK via a public member unsigned long operator()(const K& x) Equivalent keys within the collection will be grouped together based on an equality object of type EEEEQQQQ. EEEEQQQQ must ensure this grouping via public member bool operator()(const K& x, const K& y) which should return ttttrrrruuuueeee if xxxx and yyyy are equivalent. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> will not accept a key that compares equal to any key already in the collection. (RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> may contain multiple keys that compare equal to each other.) Equality is based on the comparison object and not on the ======== operator. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Isomorphic PPPPaaaaggggeeee 1111 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) Examples // // tphmap.cpp // #include<rw/tphdict.h> #include<rw/cstring.h> #include<iostream.h> struct silly_hash{ unsigned long operator()(RWCString x) const { return x.length() * (long)x(0); } }; int main(){ RWCString snd = "Second"; RWTPtrHashMap<RWCString,int,silly_hash,equal_to<RWCString> > contest; contest.insert(new RWCString("First"), new int(7)); contest.insert(&snd,new int(3)); //duplicate insertion rejected contest.insert(&snd,new int(6)); contest.insert(new RWCString("Third"), new int(2)); cout << "There was " << contest.occurrencesOf(new RWCString("Second")) << " second place winner." << endl; return 0; } Program Output: There was 1 second place winner. RRRReeeellllaaaatttteeeedddd CCCCllllaaaasssssssseeeessss Class RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> offers the same interface to a pointer-based collection that accepts multiple keys that compare equal to each other. Class rrrrwwww____hhhhaaaasssshhhhmmmmaaaapppp<<<<KKKK****,,,,TTTT****,rrrrwwww____ddddeeeerrrreeeeffff____hhhhaaaasssshhhh<<<<HHHH,,,,KKKK>>>>,rrrrwwww____ddddeeeerrrreeeeffff____ccccoooommmmppppaaaarrrreeee<<<<CCCC,,,,KKKK>>>> >>>> is the C++- standard library style collection that serves as the underlying implementation for this collection. PPPPaaaaggggeeee 2222 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) Public Typedefs typedef rw_deref_hash<H,K> container_hash; typedef rw_deref_compare<EQ,K> container_eq; typedef rw_hashmap<K*,T*,container_hash,container_eq > container_type; typedef container_type::size_type size_type; typedef container_type::difference_type difference_type; typedef container_type::iterator iterator; typedef container_type::const_iterator const_iterator; typedef pair <K* const, T*> value_type; typedef pair <K* const, T*>& reference; typedef const pair <K* const, T*>& const_reference; typedef K* value_type_key; typedef T* value_type_data; typedef K*& reference_key; typedef T*& reference_data; typedef const K*const& const_reference_key; typedef const T*const& const_reference_data; PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>>(); Constructs an empty map. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>>(const RWTPtrHashMap<K,T,H,EQ>& rwm); Copy constructor. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (const container_type & m); Constructs a pointer based hash map by copying all elements from mmmm. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (const H& h, size_type sz = RWDEFAULT_CAPACITY); This TTTToooooooollllssss....hhhh++++++++ 6.x style constructor creates an empty hashed map which uses the hash object hhhh and has an initial capacity of sssszzzz. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (const value_type* first,value_type* last); Constructs a map by copying elements from the array of ppppaaaaiiiirrrrs pointed to PPPPaaaaggggeeee 3333 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) by ffffiiiirrrrsssstttt, up to, but not including, the pair pointed to by llllaaaasssstttt. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss RWTPtrHashMap<K,T,H,EQ>& ooooppppeeeerrrraaaattttoooorrrr====(const container_type& m); RWTPtrHashMap<K,T,H,EQ>& ooooppppeeeerrrraaaattttoooorrrr====(const RWTPtrHashMap<K,T,H,EQ>& m); Destroys all associations in self and replaces them by copying all associations from mmmm. bool ooooppppeeeerrrraaaattttoooorrrr========(const RWTPtrHashMap<K,T,H,EQ>& m) const; Returns ttttrrrruuuueeee if self compares equal to mmmm, otherwise returns ffffaaaallllsssseeee. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual keys that compare equal to each other. Keys are dereferenced before being compared. T*& ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](K* key); Looks up kkkkeeeeyyyy and returns a reference to its associated item. If the key is not in the dictionary, then it will be added with an associated uninitialized pointer of type TTTT****. Because of this, if there is a possibility that a key will not be in the dictionary, then this operator should only be used as an lvalue. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppllllyyyy(void (*fn)(const K*, T*&,void*),void* d); void aaaappppppppllllyyyy(void (*fn)(const K*,const T*,void*),void* d) const; Applies the user-defined function pointed to by ffffnnnn to every association in the collection. self function must have one of the prototypes: void yourfun(const K* key, T*& a, void* d); void yourfun(const K* key, const T* a, void* d); Client data may be passed through parameter dddd. PPPPaaaaggggeeee 4444 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) void aaaappppppppllllyyyyTTTTooooKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(void (*fn)(const K*, T*&,void*),void* d); void aaaappppppppllllyyyyTTTTooooKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee (void (*fn)(const K*, const T*, void*), void* d) const; This is a deprecated version of the aaaappppppppllllyyyy member above. It behaves exactly the same as aaaappppppppllllyyyy. iterator bbbbeeeeggggiiiinnnn(); const_iterator bbbbeeeeggggiiiinnnn() const; Returns an iterator positioned at the first pair in self. size_type ccccaaaappppaaaacccciiiittttyyyy() const; Returns the number of buckets(slots) available in the underlying hash representation. See rrrreeeessssiiiizzzzeeee below. void cccclllleeeeaaaarrrr(); Clears the collection by removing all items from self. void cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy(); Removes all associations from the collection and uses ooooppppeeeerrrraaaattttoooorrrr ddddeeeelllleeeetttteeee to destroy the objects pointed to by the keys and their associated items. Do not use self method if multiple pointers to the same object are stored. (If the equality operator is reflexive, the container cannot hold such multiple pointers.) bool ccccoooonnnnttttaaaaiiiinnnnssss(const K* key) const; Returns ttttrrrruuuueeee if there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, otherwise returns ffffaaaallllsssseeee. bool ccccoooonnnnttttaaaaiiiinnnnssss ((((bbbboooooooollll ((((****ffffnnnn))))((((vvvvaaaalllluuuueeee____ttttyyyyppppeeee,,,,vvvvooooiiiidddd****)))),,,,vvvvooooiiiidddd**** dddd)))) ccccoooonnnnsssstttt;;;; PPPPaaaaggggeeee 5555 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) Returns ttttrrrruuuueeee if there exists an association a in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee, otherwise returns ffffaaaallllsssseeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(value_type a, void* d); Client data may be passed through parameter dddd. iterator eeeennnndddd(); const_iterator eeeennnndddd() const; Returns an iterator positioned "just past" the last association in self. size_type eeeennnnttttrrrriiiieeeessss() const; Returns the number of associations in self. float ffffiiiillllllllRRRRaaaattttiiiioooo() const; Returns the ratio eeeennnnttttrrrriiiieeeessss(((())))/ccccaaaappppaaaacccciiiittttyyyy(((()))). const K* ffffiiiinnnndddd(const K* key) const; If there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, then jjjj is returned. Otherwise, returns rrrrwwwwnnnniiiillll. value_type ffffiiiinnnndddd(bool (*fn)(value_type,void*), void* d) const; If there exists an association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee, then returns aaaa. Otherwise, returns ppppaaaaiiiirrrr<<<<rrrrwwwwnnnniiiillll,,,,rrrrwwwwnnnniiiillll>>>>. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(value_type a, void* d); PPPPaaaaggggeeee 6666 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) Client data may be passed through parameter dddd. T* ffffiiiinnnnddddVVVVaaaalllluuuueeee(const K* key); const T* ffffiiiinnnnddddVVVVaaaalllluuuueeee(const K* key) const; If there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, returns the item associated with jjjj. Otherwise, returns rrrrwwwwnnnniiiillll. const K* ffffiiiinnnnddddKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(const K* key, T*& tr); const K* ffffiiiinnnnddddKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(const K* key, const T*& tr) const; If there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, assigns the item associated with jjjj to trrrr,,,, and returns jjjj. Otherwise, returns rrrrwwwwnnnniiiillll and leaves the value of ttttrrrr unchanged. bool iiiinnnnsssseeeerrrrtttt(K* key, T* a); Adds kkkkeeeeyyyy with associated item aaaa to the collection. Returns ttttrrrruuuueeee if the insertion is successful, otherwise returns ffffaaaallllsssseeee. The function will return ttttrrrruuuueeee unless the collection already holds an association with the equivalent key. bool iiiinnnnsssseeeerrrrttttKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(K* key,T* a); This is a deprecated version of the iiiinnnnsssseeeerrrrtttt member above. It behaves exactly the same as iiiinnnnsssseeeerrrrtttt. bool iiiissssEEEEmmmmppppttttyyyy() const; Returns ttttrrrruuuueeee if there are no items in the collection, ffffaaaallllsssseeee otherwise. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const K* key) const; Returns the number of keys jjjj in self that compare equal to ****kkkkeeeeyyyy. PPPPaaaaggggeeee 7777 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff (bool (*fn)(value_type,void*),void* d) const; Returns the number of associations aaaa in self such that the expression((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(value_type a, void* d); Client data may be passed through parameter dddd.... K* rrrreeeemmmmoooovvvveeee(const K* key); Removes the first association with key jjjj in self that compares equal to ****kkkkeeeeyyyy and returns jjjj. Returns rrrrwwwwnnnniiiillll if there is no such association. K* rrrreeeemmmmoooovvvveeee(bool (*fn)(value_type,void*), void* d); Removes the first association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee and returns its key. Returns rrrrwwwwnnnniiiillll if there is no such association. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(value_type a, void* d); Client data may be passed through parameter dddd. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(const K* key); Removes all associations with key jjjj in self that compare equal to ****kkkkeeeeyyyy. Returns the number of associations removed. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(bool (*fn)(value_type,void*), void* d); PPPPaaaaggggeeee 8888 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) Removes all associations aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd))))))))is ttttrrrruuuueeee. Returns the number removed. ffffnnnn points to a user- defined tester function which must have prototype: bool yourTester(value_type a, void* d); Client data may be passed through parameter dddd. void rrrreeeessssiiiizzzzeeee(size_type sz); Changes the capacity of self by creating a new hashed map with a capacity of sssszzzz . rrrreeeessssiiiizzzzeeee copies every element of self into the new container and finally swaps the internal representation of the new container with the internal representation of sssseeeellllffff. rw_hashmap<K*,T*,rw_deref_hash<H,K>,deref_compare<EQ,K>>& ssssttttdddd(); const rw_hashmap<K*,T*,rw_deref_hash<H,K>,deref_compare<EQ,K>>& ssssttttdddd() const; Returns a reference to the underlying C++-standard collection that serves as the implementation for self. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTPtrHashMap<K,T,H,EQ>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTPtrHashMap<K,T,H,EQ>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrHashMap<K,T,H,EQ>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrHashMap<K,T,H,EQ>& coll); Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrHashMap<K,T,H,EQ>*& p); RWFile& PPPPaaaaggggeeee 9999 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp((((3333CCCC++++++++)))) ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrHashMap<K,T,H,EQ>*& p); Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 11110000